package xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.presenter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import xixirupan.tmgp.tencent.com.vmeim.R;
import xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.model.ProductsBaen;

/**
 * Created by lenovo on 2016/10/20.
 */

public class BottomIndexAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static final int  TYPE1=1;
    private static final int TYPE2 = 2;
    private List<Object> lists;
    Context context;
    LayoutInflater inflater;
    public BottomIndexAdapter(List<Object> lists, Context context, LayoutInflater inflater)
    {
        this.lists =lists;
        this.context=context;
        this.inflater =inflater;
    }

    @Override
    public int getItemViewType(int position) {
        if (lists.get(position) instanceof String)
        {
            return TYPE1;

        }else if(lists.get(position) instanceof List)
        {
            return TYPE2;
        }
        return 0;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  if (viewType == TYPE1)
  {
      View view = inflater.inflate(R.layout.inner_item5index_layout, parent, false);
      INViewHolder1 holder1 =new INViewHolder1(view);
      return holder1;
  }else  if (viewType ==TYPE2)
  {
      View view = inflater.inflate(R.layout.inner_item5_index_layout, parent, false);
      INViewHolder2 holder2 =new INViewHolder2(view);
      return holder2;
  }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof INViewHolder1)
        {
           String uri   = (String) lists.get(position);
            Glide.with(context).load(uri).into(((INViewHolder1) holder).imageView);
        }else if(holder instanceof INViewHolder2)
        {
            List<ProductsBaen> products = (List<ProductsBaen>) lists.get(position);
            ((INViewHolder2) holder).recyclerView.setLayoutManager(
                    new GridLayoutManager(context,1, LinearLayoutManager.HORIZONTAL,false));
            Item5RecyAdapter adapter =new Item5RecyAdapter(products,context,inflater);
             ((INViewHolder2) holder).recyclerView.setAdapter(adapter);

        }
    }

    @Override
    public int getItemCount() {
        return lists.size();
    }
    class INViewHolder1 extends RecyclerView.ViewHolder
    {
        ImageView imageView;

        public INViewHolder1(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.inner_recyc_item5);
        }
    }
    class INViewHolder2 extends RecyclerView.ViewHolder
    {
      RecyclerView recyclerView;

        public INViewHolder2(View itemView) {
            super(itemView);
            recyclerView = (RecyclerView) itemView.findViewById(R.id.inner_item5_recycler);
        }
    }
}
